package com.cheboohui.iqs.taiping.direct.e;

import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.config.Config;
import com.cheboohui.iqs.taiping.direct.DirectTp;
import com.cheboohui.iqs.taiping.direct.PublicNew;
import com.cheboohui.iqs.taiping.direct.RequestHead;
import com.cheboohui.iqs.taiping.direct.ResTaiPing;

/**
 * E05-车型查询
 * 
 * @author xielonghai
 * @version 2016-07-07
 */
public class E05Request {

	/**
	 * 车型查询-接口方法
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param brandName
	 *            品牌型号--支持模糊查询
	 * @return
	 */
	public static ResTaiPing requestE05(String session, String brandName) {
		String value = Config.value + ":辅助接口--根据厂牌型号:" + brandName + ",查询车型";

		String[] key = { "vehicle" };

		return DirectTp.request(value, PublicNew.REQUEST_URL + "/carType", getRequest(session, brandName), key);
	}

	/**
	 * 获取--E05-车型查询------请求参数
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param brandName
	 *            品牌型号
	 * @return
	 */
	private static String getRequest(String session, String brandName) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";
		// request = request + "\n\t" + "<clientName>" +
		// head.getString("clientName") + "</clientName>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		request = request + "\n\t" + "<vehicle>";
		request = request + "\n\t\t" + "<brandName>" + brandName + "</brandName>";// 品牌型号
		request = request + "\n\t" + "</vehicle>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}
}
